const api = require('../../../utils/interface.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cardId:"",
    paySwitch:"",
    password:""
  },
  onLoad: function (options) {
    // this.data.paySwitch = options.paySwitch
    this.data.cardId = options.cardId
    this.memberCardetails(options.cardId)
  },
  switch2Change(e){
    if (!this.data.password){
      this.setData({
        paySwitch:0
      })
      wx.showModal({
        title: '提示',
        content: '当前会员卡未设置密码',
      })
      return false
    }
    let paySwitch = ''
    if (e.detail.value){
      paySwitch=1
    }else{
      paySwitch=0
    }
    api.updatePaySwitch({ memberCardId: this.data.cardId, paySwitch: paySwitch}).then(res => {
      console.log(res.data)
      wx.showModal({
        title: '提示',
        content: '修改成功',
        showCancel:false
      })
    })
  },
  setPass(){
    wx.navigateTo({
      url: '/pages/userset/password/password?id=' + this.data.cardId,
    })
  },
  // 会员卡详情
  memberCardetails(id) {
    api.selectDetailsById({
      memberCardId: id
    }).then(res => {
      console.log(res.data.result)
      if (!res.data.result.password){
        this.setData({
          paySwitch:0,
          password: res.data.result.password
        })
      }else{
        this.setData({
          paySwitch: res.data.result.paySwitch,
          password: res.data.result.password
        })
      }
      
      console.log(this.data.password)
    })
  },
})